<?php //echo "<pre>"; print_r($pBerkas);die();?>
<?php $this -> load -> view('header'); ?>
<!-- BEGIN CONTAINER -->
<div class="page-container row-fluid">
	<?php //$this->load->view('sidebar');?>
	<!-- BEGIN PAGE -->
	<div class="page-content">
		<!-- BEGIN SAMPLE PORTLET CONFIGURATION MODAL FORM-->
		<div id="portlet-config" class="modal hide">
			<div class="modal-header">
				<button data-dismiss="modal" class="close" type="button"></button>
				<h3>portlet Settings</h3>
			</div>
			<div class="modal-body">
				<p>
					Here will be a configuration form
				</p>
			</div>
		</div>
		<!-- END SAMPLE PORTLET CONFIGURATION MODAL FORM-->
		<!-- BEGIN PAGE CONTAINER-->
		<div class="container-fluid">
			<!-- BEGIN PAGE HEADER-->
			<div class="row-fluid">
				<div class="span12">
					<!-- BEGIN PAGE TITLE & BREADCRUMB-->
					<h3 class="page-title"> Laporan Final </h3>
					<?php $this -> load -> view('breadcrumb'); ?>
					<!-- END PAGE TITLE & BREADCRUMB-->
				</div>
			</div>
			<!-- END PAGE HEADER-->
			<!-- BEGIN PAGE CONTENT-->
			<div class="row-fluid">
				<div class="span12">
					<!-- BEGIN EXAMPLE TABLE PORTLET-->
					<div class="portlet box blue">
						<div class="portlet-title">
							<h4><i class="icon-edit"></i>Rekapitulasi Peserta Pelatihan</h4>
							<!--<div class="tools" >
								<a href="javascript:;" class="reload"></a>
							</div>-->
														
							<div class="actions" style="padding-right: 0px">
								<a href="<?php echo base_url()?>report/rekapTrainingParticipant" class="btn green"><i class="icon-print"></i>PDF</a>
						<!--		<a href="#" class="btn green"><i class="icon-tasks"></i> Pdf</a>
								<a href="#" class="btn green"><i class="icon-envelope"></i> Excel</a>-->								
							</div>
							
						</div>
						<div class="portlet-body">
							<?php $this->load->view('report/searchBar');?>
							<table class="table table-striped table-hover table-bordered" >
								<thead>
									<tr>
								    <th rowspan="2">No</th>
								    <th rowspan="2" >Jenis Pelatihan</th>
								    <th rowspan="2">Jumlah Laporan</th>
								    <th rowspan="2">Jumlah Peserta</th>   
								    <th colspan="2">Staff</th>
								    <th colspan="2">Non Staff</th>
								    <!--<th colspan="2">Lainnya</th>--> 
								    <th colspan="2">Total</th>  
								    <th rowspan="2">Lainnya</th>
								    
								  </tr>
								  <tr>
								    <th>Laki-Laki</th>
								    <th>Perempuan</th>
								    <th>Laki-Laki</th>
								    <th>Perempuan</th>
								    <th>Laki-Laki</th>
								    <th>Perempuan</th>
								    <!--<th>Laki-Laki</th>
								    <th>Perempuan</th>-->
								  </tr>
								</thead>
								<tbody>
								<?php
									$i=1; 
									foreach ($reports as $row){ ?>
									<tr >
										<td ><?php echo $i;?></td>
										<td style="text-align: left"><?php echo $row['jenisTraining']?></td>
										<td><?php echo $row['jumlahBerkas']?></td>
										<td><?php if ($row['staffLaki'] + $row['nonStaffLaki'] + $row['staffPr'] + $row['nonStaffPr']> 0) echo $row['staffLaki'] + $row['nonStaffLaki'] + $row['staffPr'] + $row['nonStaffPr']; else echo '-';?></td> 
										<td><?php if ($row['staffLaki'] > 0) echo $row['staffLaki']; else echo '-';?></td>										
										<td><?php if ($row['staffPr'] > 0) echo $row['staffPr']; else echo '-'; ?></td>
										<td><?php if ($row['nonStaffLaki'] > 0) echo $row['nonStaffLaki']; else echo '-';?></td>
										<td><?php if ($row['nonStaffPr'] > 0) echo $row['nonStaffPr']; else echo '-';?></td>
										<td><?php if ($row['staffLaki'] + $row['nonStaffLaki'] > 0) echo $row['staffLaki'] + $row['nonStaffLaki']; else echo '-';?></td>
										<td><?php if ($row['staffPr'] + $row['nonStaffPr']> 0) echo $row['staffPr'] + $row['nonStaffPr']; else echo '-';?></td>
										<td><?php if ($row['lainnyaLaki'] > 0) echo $row['lainnyaLaki'] + $row['lainnyaPr']; else echo '-';?></td>
										<!--<td><?php if ($row['lainnyaPr'] > 0) echo $row['lainnyaPr']; else echo '-';?></td>-->
									</tr>		
								<?php	$i++;} ?>
								</tbody>
							</table>
							<div class="row-fluid">
								<?php //$this->load->view('paging', $pBerkas);?>
							</div>
						</div>
					</div>
					<!-- END EXAMPLE TABLE PORTLET-->
				</div>
			</div>
			<!-- END PAGE CONTENT -->
		</div>
		<!-- END PAGE CONTAINER-->
	</div>
	<!-- END PAGE -->
</div>
<!-- END CONTAINER -->
<div style="display: none">
	<form action="" method="post" id="formReport">
		<input type="hidden" name="id" id="inputId"/>
		<input type="hidden" name="Profile.id" id="inputProfile" value="6"/>
		<input type="hidden" name="BerkasComment.text" id="berkasNote"/>
	</form>
</div>

<?php $this->load->view('footer')?>

<script>
	$(document).ready(function() {
		$('#distrik').on('change', function(e) {
		    console.log("district value changed");
		    	var distrikId = $('#distrik').val();
		    	if (distrikId == "-1"){
		    		return;
		    	}
		    	// GET LIBRARY COMBOBOX
		    	$("#desa").empty();
				$("#desa").append($("<option></option>").attr("value", "-1").text("--Semua--")); 
		    	$.ajax({
				  url: "<?php echo base_url()?>/reference/desaByDistrik/"+distrikId,
				  success: function(data){
				  	 	/*if (data.error == 1){
				  			console.log("ERROR FETCHING DISTRIK");						
				  		} 				  		
				  	 	if (data.success == 1){
				  	 		
				  	 	} */
				  	 	
				  	 	$.each(data, function(key, val) {
							 $("#desa").append($("<option></option>")
							 .attr("value", val.value).text(val.nama));
						});
						$('#desa').trigger("liszt:updated");
				  },
				  dataType: "json"
				});
				// END GET LIBRARY COMBOBOX
		  });
		  
		  $('#tipeBerkas').on('change', function(e) {
		    	console.log("district value changed");
		    	if ($(this).val() == "TRAINING"){
		    		// GET LIBRARY COMBOBOX
			    	$("#rincianLaporan").empty();
					$("#rincianLaporan").append($("<option></option>").attr("value", "-1").text("--Semua--")); 
			    	$.ajax({
					  url: "<?php echo base_url()?>/reference/jenisTraining",
					  success: function(data){
					  	 	$.each(data, function(key, val) {
								 $("#rincianLaporan").append($("<option></option>")
								 .attr("value", val.value).text(val.nama));
							});
							$('#rincianLaporan').trigger("liszt:updated");
					  },
					  dataType: "json"
					});
		    	} else {
		    				    		
		    	}		   		 	
		  });
		  
		 $('#btnCari').click(function(){
			var distrikId = $('#distrik').val();
			var desaId = $('#desa').val();
			var tipeBerkasId = $('#tipeBerkas').val();
			var rincianLaporan = $('#rincianLaporan').val();
			var url = base_url + 'report/findRekapLaporanByDistrikDesaTipeAndRincian/'
				+ distrikId + "/" + desaId + "/" +tipeBerkasId + "/" + rincianLaporan;
			if (distrikId != "-1" && desaId != "-1" && tipeBerkasId != "-1" && rincianLaporan != "-1"){
				$.ajax({
					url : url,
					dataType : "jsonp",
					data : {
						featureClass : "P"
					},
					success : function(data) {
						//$('#info').show();
						$("#myTable").find("tr:gt(0)").remove();
						if (data.result == "1"){
							var html = '';
							$.map(data.hasil, function(item) {
								html += '<TR>'
								      + '<TD>' + item.no + '</TD>'
								      + '<TD>' + item.noTest + '</TD>'
								      + '<TD>' + item.nama + '</TD>'
										+ '</TR>';
							});
							$('#myTable tr:last').after(html);

							// paging
							var paging1 = '';
							if (data.count == 0){
								paging1 = 'Showing ' + data.index + ' to ' + data.part2 + 'of ' + data.count + ' entries';
							} else {
								paging1 = 'Showing ' + (data.index + 1) + ' to ' + data.part2 + 'of ' + data.count + ' entries';
							}
							
							//$('#paging').append(paging1);
							var paging2 = '<ul>';
							var prev = '';
							if (data.activePage == 1){
								prev = '<li class="prev disabled">'
											+'<a href="#"> Prev</a>'
										+'</li>';
							} else {
								prev = '<li class="prev">'
											+'<a href="#" id="linkPagePrev" onClick="handleGoToPage(event, '+(data.activePage-1)+')"> Prev</a>'
										+'</li>';
							}
							maxPage = data.numpage;
							var activePage = data.activePage;
							var x = (activePage/10) * 10;
							
							if (data.numpage < (x + 10)){
								x = data.numpage - 10; 
							} else if (data.numpage == (x+10)){
								x = x-1;
							} else if (x % 10 == 0) {
								if (x>=10){
									x = x - 1;
								}
							}
							
							var j = 0;
							if (x < 0){
								x = 0;
								j = data.numpage;
							} else {
								j = 10;	
							}
							var nav = '';
							for (var i=1;i<=j;i++){								
								if ((x+i) == activePage){ 
									nav = nav + '<li class="active">';		
						 		} else { 
									nav = nav + '<li>';
						 		}  
								nav = nav + '<a href="#" onClick="handleGoToPage(event,' + (x+i) + ')">' + (x+i) + '</a></li>';	
								          
						 	}

						 	var next = '';
						 	if (activePage >= data.numpage){
								next = "<li class='next disabled'><a href='#'>Next </a></li>";	
							} else {
								next = "<li class='next'><a href='#' onClick='handleGoToPage(event, " + (activePage+1) + ")'>Next</a></li>";
							}

						 	paging2 = paging2 + prev + nav + next + '</ul>';
						 	$('#paging').html(paging2);		
						 	$('#paging').show();														
						}											
					}
				});					
			}			
		});
 
	});
</script>